﻿Public Class frmOptions

    Public blnCheckingUncheckingBoxes As Boolean

    Private Sub frmOptions_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
            If Form1.URLShorteners(intCounter).strShortenerURL.StartsWith(LCase(e.KeyChar)) Then
                Me.pnlEnabledURLShorteners.ScrollControlIntoView(Form1.URLShorteners(intCounter).chkCheckbox)
                Exit For
            End If
        Next
    End Sub

    Private Sub frmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
            Form1.URLShorteners(intCounter).chkCheckbox = New Form1.ShortenerCheckboxes
        Next
        Form1.URLShorteners(0).chkCheckbox.Location = New System.Drawing.Point(3, 3)
        Form1.URLShorteners(0).chkCheckbox.Text = Form1.URLShorteners(0).strShortenerURL
        Form1.URLShorteners(0).chkCheckbox.Checked = Form1.URLShorteners(0).EnabledSetting
        Form1.URLShorteners(1).chkCheckbox.Location = New System.Drawing.Point(135, 3)
        Form1.URLShorteners(1).chkCheckbox.Text = Form1.URLShorteners(1).strShortenerURL
        Form1.URLShorteners(1).chkCheckbox.Checked = Form1.URLShorteners(1).EnabledSetting
        For intCounter As Integer = 2 To Form1.URLShorteners.Length - 1
            Form1.URLShorteners(intCounter).chkCheckbox.Text = Form1.URLShorteners(intCounter).strShortenerURL
            Form1.URLShorteners(intCounter).chkCheckbox.Checked = Form1.URLShorteners(intCounter).EnabledSetting
            Form1.URLShorteners(intCounter).chkCheckbox.Location = New System.Drawing.Point(Form1.URLShorteners(intCounter - 2).chkCheckbox.Location.X, Form1.URLShorteners(intCounter - 2).chkCheckbox.Location.Y + 23)
        Next
        For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
            Me.pnlEnabledURLShorteners.Controls.Add(Form1.URLShorteners(intCounter).chkCheckbox)
        Next
        Me.chkShowMessageAfterCopying.Checked = My.Settings.blnClipboardMessageBox
        Me.chkSortByLength.Checked = My.Settings.blnSortByLength
        Me.pnlEnabledURLShorteners.Select()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        My.Settings.blnClipboardMessageBox = Me.chkShowMessageAfterCopying.Checked
        My.Settings.blnSortByLength = Me.chkSortByLength.Checked
        For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
            Form1.URLShorteners(intCounter).SaveSetting()
        Next
        My.Settings.Save()
        Form1.FindEnabledShorteners()
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub chkSelectDeselectAll_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkSelectDeselectAll.CheckedChanged
        If Me.Created = True And Me.chkSelectDeselectAll.CheckState <> CheckState.Indeterminate Then
            blnCheckingUncheckingBoxes = True
            If Me.chkSelectDeselectAll.Checked = True Then
                For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
                    Form1.URLShorteners(intCounter).chkCheckbox.Checked = True
                Next
            Else
                For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
                    Form1.URLShorteners(intCounter).chkCheckbox.Checked = False
                Next
            End If
            blnCheckingUncheckingBoxes = False
        End If
    End Sub
End Class